﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;

namespace Howork
{
    public partial class QueryRecord : System.Web.UI.Page
    {
        protected string GetJson<T>(T obj)
        {
            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(obj.GetType());
            using (MemoryStream stream = new MemoryStream())
            {
                jsonSerializer.WriteObject(stream, obj);
                string jsonString = Encoding.UTF8.GetString(stream.ToArray());
                return jsonString;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string begin_time = Request["begin"];
            string end_time = Request["end"];
            
            DateTime dt_begin = DateTime.Parse(begin_time);
            DateTime dt_end = DateTime.Parse(end_time);
            
            DBAdapter db = new DBAdapter();
            List<QjRecord> record_list = db.getQjRecord(dt_begin,dt_end);

            string jsonString = GetJson<List<QjRecord>>(record_list);
            Response.Write(jsonString);
            Response.End();
        }
    }
}